<template>
  <div class="record-list">
    <van-list ref="van-list" v-model="loading"
    :finished-text="finished && !ListInfo.length ? '' : '没有更多了'"
    :finished="finished" @load="getListInfo">
      <div class="cell van-hairline--bottom" v-for="(item, index) in ListInfo" :key="index">
        <div class="record">
          <div class="left-info">
            <p class="time">最近浏览：{{ item.updateTimeStr }}</p>
            <p class="title">
              <span class="name">{{ item.clientName }}</span>
              <span class="name-bold">{{ showText(item) }}</span>
            </p>
          </div>
          <div class="right-info">
            <p class="num">{{ item.dynamicCount }}</p>
            <p class="text">浏览次数</p>
          </div>
        </div>
      </div>
    </van-list>
  </div>
</template>

<script>
import dynamicsService from 'SERVICE/dynamicsService'
export default {
  data() {
    return {
      loading: false,
      finished: false,
      ListInfo: []
    }
  },
  methods: {
    showText(item) {
      let str = item.markedWords
      if (!str) return ''
      str = str.replace(/{{(.+?)}}/, '' )
      str = str.replace(/{{/g, '' )
      str = str.replace(/}}/g, '' )
      // var regex = /{{(.+?)}}/g
      // let matchArray = str.match(regex)
      // matchArray[0] = ''
      // if (matchArray[1]) {
      //   matchArray[1] = matchArray[1].slice(2, matchArray[1].length - 2)
      // } 
      // matchArray.forEach(item => {
      //   str = str.replace(/{{(.+?)}}/, item )
      // })
      return str
    },
    async getListInfo() {
      let clientId = this.$route.params.id
      let result = await dynamicsService.getScanArticleDynamicList(clientId)
      if (result.pages <= this.page) {
        this.finished = true
      } else {
        this.page +=1
      }
      this.loading = false
      this.finished = true
      this.ListInfo = this.ListInfo.concat(result.records)
    },
  }
}
</script>

<style lang="less" scoped>
.record-list {
  background: #f7f9fa;
  // padding: 20px 0;
  .cell {
    background: #fff;
    padding: 20px 16px;
  }
  .record {
    display: flex;
    align-items: center;
    .left-info {
      flex: 1;
      .time {
        font-size: 14px;
        color: #9BA4B4;
        line-height: 20px;
        padding-bottom: 4px;
      }
      .title {
        font-size: 14px;
        color: #13284D;
        line-height: 20px;
        font-weight: 500;
        .name {
          color: #007AE6;
        }
        .name-bold {
          padding: 0 5px;
          color: #13284D;
        }
      }
    }
    .right-info {
      flex-basis: 50px;
      text-align: center;
      margin-left: 10px;
      .num {
        font-size: 20px;
        color: #13284D;
      }
      .text {
        font-size: 10px;
        color: #9BA4B4;
        line-height: 20px;
      }
    }
  }
}
</style>